<?php
namespace app\admin\model;


use app\model\Base;

class Orders extends Base
{
    public function ordersGoods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id')->bind([
            'goods_cover'=>'cover',
            'amount'=>'sale_amount',
            'goods_title'=>'name',
        ]);
    }

    public function getAddressFormatAttr($value, $data)
    {
        return $data['province_name'] . $data['city_name'] . $data['area_name'] . $data['address'];
    }

    public function getPayTypeFormatAttr($value, $data)
    {
        return Base::$walletTypeArray[$data['pay_type']] . "付款";
    }

    public function getTotalAmountFormatAttr($value, $data)
    {
        return bcdiv_amount($data['total_amount']);
    }

    public function getShipFormatAttr($value, $data)
    {
        return Base::$shipStatusArray[$data['ship_status']];
    }

    public function getNameFormatAttr($value, $data)
    {
        return UserBank::where('user_id', $data['user_id'])->value('real_name');
    }

    public function getPhoneFormatAttr($value, $data)
    {
        return User::where('id', $data['user_id'])->value('phone');
    }

    public function getPriceFormatAttr($value, $data)
    {
        $price = BenefitProduct::where('id', $data['product_id'])->value('price');
        return $price;
    }

    public function userinfo()
    {
        return $this->hasOne(User::class, 'id', 'user_id')
            ->bind([
                'userstatus'=>'status',
            ]);
    }
}